package com.neu.service.impl;

import com.neu.client.ProductClient;
import com.neu.dto.BookDTO;
import com.neu.mapper.BookMapper;
import com.neu.service.BookService;
import com.neu.utils.ResultModel;
import com.neu.vo.BookVO;
import com.neu.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    //@Autowired
    //RestTemplate restTemplate;  //发送请求的模版

    @Autowired
    ProductClient productClient;

    @Autowired
    BookMapper bookMapper;

    @Override
    public int add(int productId) {

        //获取商品的详细信息,写入到订单表;调用商品服务,让库存减1
        /*
        ResultModel resultModel = restTemplate.getForObject("http://product-service/product/"+productId, ResultModel.class);
        Map<String,Object> map = (Map<String, Object>) resultModel.getData();
        System.out.println(map);
        System.out.println("下单了");
        */

        ResultModel<ProductVO> resultModel = productClient.findById(productId);
        System.out.println("购买了" + resultModel.getData().getName() + "商品");

        return 1;
    }

    @Override
    public List<BookVO> find(BookDTO bookDTO) {
        return bookMapper.find(bookDTO);
    }


}
